/**
 * Created with IntelliJ IDEA.
 * Description: LCR 179. 查找总价格为目标值的两个商品
 * User: Spider-Man
 * Date: 2025-03-16
 * Time: 22:46
 */
public class Price {
    public static int[] twoSum(int[] price, int target) {
        int left = 0;
        int right = price.length - 1;
        while (left < right) {
            int sum = price[left] + price[right];
            if (sum > target) {
                right--;
            } else if (sum < target) {
                left++;
            } else {
                return new int[]{price[left], price[right]};
            }
        }
        return new int[]{0};
    }

    public static void main(String[] args) {
        int[] price = {8, 21, 27, 34, 52, 66};
        int target = 61;
        int[] n = twoSum(price, target);
    }
}
